package cn.iocoder.devlop.module.annual.report.config;

import cn.iocoder.devlop.module.annual.report.handler.TableNameSuffixHandler;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author Euan
 * @since 2024/1/22
 */
@Configuration
public class MybatisPlusConfig {

    @Resource
    private MybatisPlusInterceptor mybatisPlusInterceptor;

    @PostConstruct
    public void addInterceptor() {
        if (mybatisPlusInterceptor == null) {
            // 如果基础jar包中的 MybatisPlusInterceptor 没有被定义，则创建一个新的实例
            mybatisPlusInterceptor = new MybatisPlusInterceptor();
        }
        DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor = new DynamicTableNameInnerInterceptor();
        dynamicTableNameInnerInterceptor.setTableNameHandler(new TableNameSuffixHandler());
        mybatisPlusInterceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor);
    }

//    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig config = new GlobalConfig();
        // 设置不使用``包裹数据库字段
        config.setDbConfig(new GlobalConfig.DbConfig().setColumnFormat("%s"));
        return config;
    }


}
